/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($http,httpservice,$q) {
    var caseBarDetailZhengService = {};



    /*证据分组*/
    caseBarDetailZhengService.getETypeList = function () {
        //var params={"caseId":caseId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getETypeUrl,
            //params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    //获取证据组接口列表
    caseBarDetailZhengService.getEGroupList = function (caseId) {
        var params={"caseid":caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEGroupUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //获取证据池列表接口
    caseBarDetailZhengService.getEPollList = function (caseId,evidenceGroupId,isAll,pageNum,pageSize) {
        var params={"caseid":caseId,"evidenceGroupId":evidenceGroupId,"status":"0","isAll":isAll,"pageNum":pageNum,"pageSize":pageSize};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEPollUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //添加证据组
    caseBarDetailZhengService.addEGroup = function (caseId,description,evidenceGroupName,creatorId) {
        var params={"caseid":caseId,"description":description,"evidenceGroupName":evidenceGroupName,"creatorId":creatorId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addEGroupUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //证据清单,
    caseBarDetailZhengService.getEAllList = function (caseId) {
        var params={"caseid":caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEAllListUrl,
            params:params,
            responseType: 'arraybuffer',
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //添加证据/快速创建
    caseBarDetailZhengService.addE = function (caseId,evidenceName,creatorId,evidenceTypeId,evidenceGroupId) {
        var params={"caseid":caseId,"evidenceName":evidenceName,"creatorId":creatorId,"evidenceTypeId":evidenceTypeId,"evidenceGroupId":evidenceGroupId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addEUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //获取证据详情
    caseBarDetailZhengService.getEDetail = function (id) {
        var params={"id":id};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEDetailUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //删除证据组
    caseBarDetailZhengService.deleteEGroup = function (id,creatorId) {
        var params={"id":id,"status":"0","creatorId":creatorId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteEGroupUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //修改证据组名字
    caseBarDetailZhengService.updateEGroupName = function (id,evidenceGroupName,description,creatorId) {
        var params={"id":id,"status":"1","evidenceGroupName":evidenceGroupName,"description":description,"creatorId":creatorId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteEGroupUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //评论
    caseBarDetailZhengService.getEComment = function (evidenceId) {
        var params={"evidenceId":evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getECommentUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //日志
    caseBarDetailZhengService.getELog = function (evidenceId) {
        var params={"evidenceId":evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getELogUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //发布评论
    caseBarDetailZhengService.insertEComment = function (evidenceId,commentUserId,comment) {
        var params={"evidenceId":evidenceId,"commentUserId":commentUserId,"comment":comment};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.insertECommentUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //详情修改
    caseBarDetailZhengService.updateEDetail = function (params) {
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.updateEDetailUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //详情删除
    caseBarDetailZhengService.deleteEDetail = function (caseId,evidenceId,creatorId) {
        var params={"caseid":caseId,"evidenceId":evidenceId,"creatorId":creatorId,"status":"9"};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteEDetailUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //修改详情时间
    caseBarDetailZhengService.updateEDDate = function (evidenceId,creatorId,deadLine,estimateHour,actualHour) {
        var params={"evidenceId":evidenceId,"creatorId":creatorId,"status":0,"deadline":deadLine,'estimateHour':estimateHour,'actualHour':actualHour};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.updateEDDateUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //获取律师列表
    caseBarDetailZhengService.getLawyers = function (caseId,evidenceId) {
        var params={"caseid":caseId,"evidenceId":evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getLawyersUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //添加律师
    caseBarDetailZhengService.addLawyers = function (taskId,executorId,executorName,creatorId,evidenceId,evidenceName,caseId) {
        var params={"taskId":taskId,"executorId":executorId,"executorName":executorName,"creatorId":creatorId,"evidenceId":evidenceId,"evidenceName":evidenceName,"caseid":caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addLawyersUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //删除律师
    caseBarDetailZhengService.deleteLawyers = function (taskId,executorId,executorName,creatorId,evidenceId) {
        var params={"taskId":taskId,"executorId":executorId,"executorName":executorName,"creatorId":creatorId,"evidenceId":evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteLawyersUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //上传附件
    caseBarDetailZhengService.uploadFile = function (data) {
        //var params={"evidenceId":evidenceId,"creatorId":creatorId,"filename1":filename1};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.uploadFileUrl,
            data:data,
            headers: {'Content-Type': undefined},
            transformRequest: angular.identity
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //下载附件
    caseBarDetailZhengService.downLoadFile = function (filename) {
        var params={"filename":filename};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.downLoadFileUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //删除附件
    caseBarDetailZhengService.deleteFile = function (evidenceAttachedId,evidenceId,fileName,creatorId,caseId) {
        var params={"evidenceAttachedId":evidenceAttachedId,"evidenceId":evidenceId,"fileName":fileName,"creatorId":creatorId,"caseid":caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteFileUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //新删除文件
  caseBarDetailZhengService.deleteEvidenceAttr = function  (evidenceAttachedId, evidenceId) {
    var params= {"evidenceAttrId":evidenceAttachedId,"evidenceId":evidenceId};
      return $http({
        method:"POST",
        url:httpservice.deleteEvidenceAttrUrl,
        data:params,
        headers : {'Content-Type':'application/json'}
      })
    }

    //检查项--添加
  caseBarDetailZhengService.checkedEvidenceAdd = function (params) {
      return $http({
        method:"POST",
        url:httpservice.checkedEvidenceAddUrl,
        params:params,
        headers:{'Content-Type':'application/json'}
      })
  };
  //检查项--删除
  caseBarDetailZhengService.checkedEvidenceDel = function (params) {
    return $http({
      method:"POST",
      url:httpservice.checkedEvidenceDelUrl,
      params:params,
      headers:{'Content-Type':'application/json'}
    })
  };
  //检查项--编辑
  caseBarDetailZhengService.checkedEvidenceEdit = function (params) {
    return $http({
      method:"POST",
      url:httpservice.checkedEvidenceEditUrl,
      params:params,
      headers:{'Content-Type':'application/json'},
    })
  };
  //附件下载
  caseBarDetailZhengService.downloadAttachment = function (params) {
    return $http({
      method:"POST",
      url:httpservice.evidenceAccDownLoadUrl,
      params:params,
      responseType: 'arraybuffer',
      headers:{'Content-Type':'application/json'},
    })
  };
  //预览附件
  caseBarDetailZhengService.evidencePreviewAttach = function (params) {
    return $http({
      method:"POST",
      url:httpservice.evidencePreviewAttachUrl,
      params:params,
      responseType: 'arraybuffer',
      headers:{'Content-Type':'application/json'},
    })
  };

    return caseBarDetailZhengService;
};
